namespace Jzo15
{
    public class Solution
    {
        public int HammingWeight(uint n)
        {
            int weight = 0;
            while (n > 0)
            {
                weight += (int) (n % 2);
                n /= 2;
            }

            return weight;
        }
    }
    
    public class Solution_1
    {
        /// <summary>
        /// 每位判断
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int HammingWeight(uint n)
        {
            int weight = 0;
            while (n > 0)
            {
                weight += (int) (n & 1);
                n >>= 1;
            }

            return weight;
        }

        // public int HammingWeight(uint n)
        // {
        //     int weight = 0;
        //     while (n != 0)
        //     {
        //         n &= n - 1;
        //         weight++;
        //     }
        //
        //     return weight;
        // }
    }
}